package cn.ichiva.puppet.example.base.p1;

import javafx.beans.binding.StringExpression;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.fxml.FXML;
import javafx.fxml.impl.AbstractPuppetComponent;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;

/**
 * 双向绑定
 */
public class L1P1BindComponent extends AbstractPuppetComponent {

    @FXML
    StringProperty firstName = new SimpleStringProperty("");
    @FXML
    StringProperty secondName = new SimpleStringProperty("");
    @FXML
    StringExpression fullName = firstName.concat(secondName);

    @Override
    public CharSequence render() {
        imports(VBox.class, Label.class, TextField.class, HBox.class);
        return """
                <VBox>
                    <HBox>
                        <Label text="欢迎," />
                        <Label text="${fullName}" />
                    </HBox>
                     <HBox>
                        <Label text="姓" />
                        <TextField text="${firstName}" />
                    </HBox>
                    <HBox>
                        <Label text="名" />
                        <TextField text="${secondName}" />
                    </HBox>
                </VBox>
                """;
    }
}
